package com.lucker.controller.init;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.dsig.spec.ExcC14NParameterSpec;

import org.apache.commons.collections4.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lucker.common.util.AESCBCUtil;
import com.lucker.common.util.AESUtil;
import com.lucker.common.util.CommonStr;
import com.lucker.controller.BaseController;
import com.lucker.ds.model.SysRestrictionsConfig;
import com.lucker.framework.constant.ResponseBaseModel;
import com.lucker.framework.constant.ResponseResultModel;
import com.lucker.service.sys.SysRestrictionsConfigService;

@Controller
@RequestMapping(value = "init")
public class InitController extends BaseController {
	
	@Autowired
	SysRestrictionsConfigService sysRestrictionsConfigService;
	
	@RequestMapping(value="socket",method = RequestMethod.POST)
	public @ResponseBody ResponseEntity<?> commit_opencode(HttpServletRequest req) {
		try {
			
			SysRestrictionsConfig config = sysRestrictionsConfigService.getSysRestrictionsConfig("socketserver");
			
			if(config == null) {
				throw new Exception("未配置socket服务器相关信息,请从数据进行配置!");
			}
			
			Map<String,String> retMap = new HashedMap<String,String>();
			retMap.put("socketServer", AESCBCUtil.encrypt(config.getName()));
			retMap.put("socketPort", ""+config.getExperience());
			return new ResponseEntity<>(new ResponseResultModel<Map<String,String>>(retMap),HttpStatus.OK);
		}catch(Exception e) {
			this.getLoger().error("登录异常 {} , {}", e.getMessage(),e);
			return new ResponseEntity<>(new ResponseBaseModel(29002,e.getMessage()), HttpStatus.OK);
		}
		
	}

}
